<template>
  <view :style="themeColor">
    <view class="page">
      <view class="flex align-center benben-position-layout flex search_flex_0"
        :style="{height:(100+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
        <view class='flex align-center justify-between flex-sub search_fd0_0'>
          <text class='fu-iconfont2  search_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back"
            data-url="1">&#xE794;</text>
          <view class='flex align-center flex-sub search_fd0_0_c1'>
            <image class='search_fd0_0_c1_c0' mode="aspectFit" :src='STATIC_URL+"195.png"'></image>
            <benben-input class='flex-sub search_fd0_0_c1_c1' type="text" :focus='true' :placeholder="`${name}`"
              confirm-type="search" :maxlength="50" placeholder-style="color:#999;font-size:24rpx"
              @confirm="addSearchHistoryFunc()" v-model="keyword" />
            <image class='search_fd0_0_c1_c2' mode="aspectFit" :src='STATIC_URL+"196.png"' @tap="ClearInputFunc()"
              v-if=" keyword!='' &&keyword!=null"></image>
          </view>
          <view class='flex flex-wrap align-center search_fd0_0_c2' v-if=" appSystemIdentification=='Wechat'">
          </view>
        </view>

      </view>
      <view :style="{height: (100+StatusBarRpx)+'rpx'}"></view>
      <!---搜索记录flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout search_flex_1"
        v-if=" associateList.length==0 || keyword==''">
        <view class='flex flex-wrap align-center search_fd1_0'>

          <view class='flex  search_fd1_0_c0'></view>

          <text class='search_fd1_0_c1'>{{$t('历史搜索')}}</text>
          <image class='search_fd1_0_c2' mode="aspectFit" :src='STATIC_URL+"197.png"'
            @tap.stop="popupShow1661481796822=true" v-if=" appSearchHistory.length>0"></image>
        </view>
        <view class='flex flex-wrap align-center search_fd1_1'>
          <template v-for='(item,key0) in appSearchHistory'>
            <view class='flex align-center self-center justify-center search_fd1_1_c0' @tap.stop="handleJumpDiy"
              data-type="navigateTo" :data-url="`/pages/fl/commodityList/commodityList?keyword=${item.name}`"
              @longpress="handleLongpressFunc(item.name)" :key='key0'>
              <text class='self-center search_fd1_1_c0_c0'>{{item.name}}</text>
              <image class='search_fd1_1_c0_c1' mode="aspectFit" :src='STATIC_URL+"198.png"'
                @tap.stop="deleteSearchHistoryFunc(item.name)" v-if=" item.name==removeIndex"></image>
            </view>
          </template>

        </view>
        <text class='search_fd1_2' v-if=" appSearchHistory.length==0">{{$t('暂无历史记录')}}</text>
      </view>

      <!---搜索记录flex布局结束-->
      <benben-popup v-model="popupShow1661481796822" :mask="true" :mask-close-able="true" mode='center'>
        <!---删除历史记录弹窗flex布局开始-->
        <view class="flex flex-direction flex-wrap align-center search_flex_2">
          <text class='search_fd2_0'>{{$t('提示')}}</text>
          <text class='search_fd2_1'>{{$t('确定删除历史记录？')}}</text>
          <view class='flex flex-wrap align-center search_fd2_2'>
            <button class='search_fd2_2_c0' @tap.stop="popupShow1661481796822=false">{{$t('取消')}}</button>
            <button class='search_fd2_2_c1' @tap.stop="emptySearchHistoryFunc()">{{$t('确定')}}</button>
          </view>
        </view>

        <!---删除历史记录弹窗flex布局结束-->

      </benben-popup>


    </view>
  </view>
</template>
<script>
  import {
    validate
  } from '@/common/utils/validate.js'

  export default {
    components: {},


    data() {
      return {
        "popupShow1661481796822": false,
        "dataLists": [],
        "removeIndex": -1,
        "xainshi": false,
        "associateList": [],
        "inputList": [],
        "is_zhuan": false,
        "showIcon": "1",
        "name": "",
        keyword: ''
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },
      appSearchHistory() { // 搜索历史
        return this.$store.state.appSearchHistory
      },
      /**
       * @returns
       * Android       安卓
       * IOS       苹果
       * Web       H5 或 pc
       * Wechat       微信小程序
       * Alipay       支付宝小程序
       * Baidu       百度小程序
       * ByteBounce       抖音小程序
       * 360       360小程序
       * FastApp       快应用
       */
      appSystemIdentification() {
        return this.$store.state.appSystemIdentification
      }
    },
    watch: {},
    onLoad(options) {
      let {
        name
      } = options
      if (name !== undefined) this.name = name
      this.fullNetworkHotSearchFunc()
      this.searchForFunc()
      this.geiinputListFunc()
      this.initTimerFunc()
    },
    onUnload() {
      this.offTimerFunc()
    },
    onReady() {

    },
    onShow() {

    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {
      this.fullNetworkHotSearchFunc()
      this.changeSweetGrilFunc()
      this.geiinputListFunc()
    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      //搜索
      async searchForFunc() {
        if (this.name == "") {
          this.name = global.i18n.t('请输入商品名称')
        }
        this.is_zhuan = true;
        setTimeout(() => {
          this.is_zhuan = false;
        }, 2000)
        //请求方法
        //数据验证

        // let data = await this.$api.get(, {

        // });

        // if (data.data.code != 1) {
        //   this.$message.info(data.data.msg);
        //   return
        // }



      },
      //全网热搜
      async fullNetworkHotSearchFunc() {
        //请求方法
        //数据验证

        let datadataLists = await this.$api.get(global.apiUrls.post641afd26102ab, {

        });

        if (datadataLists.data.code != 1) {
          this.$message.info(datadataLists.data.msg);
          return
        }
        let infodataLists = datadataLists.data;
        this.dataLists = infodataLists.data

      },
      //换一批
      changeSweetGrilFunc() {
        this.$util.debounce(() => {
          this.searchForFunc();
        }, 300);
      },
      //长按事件
      handleLongpressFunc(index) {
        this.removeIndex = index;
      },
      //添加搜索历史
      addSearchHistoryFunc() {
        if (!this.keyword && this.name != global.i18n.t('请输入商品名称')) {
          this.keyword = this.name;
        }
        if (this.keyword) {
          this.$store.commit('appSearchHistoryAdd', {
            "name": this.keyword
          })
          this.$urouter.navigateTo(`/pages/fl/commodityList/commodityList?keyword=${this.keyword}`);
        } else {
          this.$urouter.navigateTo(`/pages/fl/commodityList/commodityList`);
        }
      },
      //删除搜索历史
      deleteSearchHistoryFunc(name) {
        this.$store.commit('appSearchHistoryDel', {
          "name": name
        })
      },
      //清空搜索记录
      emptySearchHistoryFunc() {
        this.$store.commit('appSearchHistoryClean', '')
        this.popupShow1661481796822 = false;
      },
      //搜索框输入内容
      async searchFunc() {
        if (this.keyword != '') {
          //请求方法
          //数据验证

          let dataassociateList = await this.$api.aGet(global.apiUrls.post64184ac1cafc3, {

          });

          if (dataassociateList.data.code != 1) {
            this.$message.info(dataassociateList.data.msg);
            return
          }
          let infoassociateList = dataassociateList.data.data;
          this.associateList = infoassociateList.data

          if (this.associateList.length != 0) {
            this.xainshi = true;
          }
        }
      },
      //清空输入框
      ClearInputFunc() {
        this.keyword = '';
        this.name = global.i18n.t('请输入商品名称')
      },
      //点击发现
      clickDiscoverFunc(name) {
        this.$store.commit('appSearchHistoryAdd', {
          "name": name
        })
        this.$urouter.navigateTo(`/pages/fl/commodityList/commodityList?keyword=${name}`);
      },
      //获取输入框搜索发现
      async geiinputListFunc() {
        //请求方法
        //数据验证

        let datainputList = await this.$api.get(global.apiUrls.post641af9cb8b32f, {
          view_position: 'input'
        });

        if (datainputList.data.code != 1) {
          this.$message.info(datainputList.data.msg);
          return
        }
        let infoinputList = datainputList.data;
        this.inputList = infoinputList.data

      },
      //初始化图标定时器
      initTimerFunc() {
        this.Timer = setInterval(() => {
          this.showIcon = 0
          setTimeout(() => {
            this.showIcon = 1
          }, 200)
        }, 2000)
      },
      //移除图标定时器
      offTimerFunc() {
        clearInterval(this.Timer)
      }
    }
  };
</script>
<style lang="scss" scoped>
  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: var(--benbenbgColor1);
    background-size: 100% auto;
  }

  .search_flex_0 {
    background: var(--benbenbgColor1);
    width: 750rpx;
    height: 100rpx;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto !important;
  }

  .search_fd0_0_c2 {
    width: 30%;
  }

  .search_fd0_0_c1_c2 {
    width: 38rpx;
    height: 38rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .search_fd0_0_c1_c1 {
    margin: 0rpx 16rpx 0rpx 16rpx;
    font-size: 24rpx;
    font-weight: 400;
    color: #333;
    height: 64rpx;
  }

  .search_fd0_0_c1_c0 {
    width: 24rpx;
    height: 24rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .search_fd0_0_c1 {
    background: rgba(246, 247, 249, 1);
    background-size: 100% auto !important;
    border-radius: 34rpx 34rpx 34rpx 34rpx;
    margin: 0rpx 0rpx 0rpx 24rpx;
    padding: 0rpx 24rpx 0rpx 24rpx;
    height: 64rpx;
  }

  .search_fd0_0_c0 {
    font-size: 36rpx;
    color: #333;
    font-weight: 500;
  }

  .search_fd0_0 {
    margin: 17rpx 32rpx 24rpx 32rpx;
  }

  .search_flex_1 {
    padding: 0rpx 0rpx 0rpx 0rpx;
  }

  .search_fd1_2 {
    font-size: 24rpx;
    font-weight: 400;
    color: #666666;
    margin: 0rpx 0rpx 32rpx 24rpx;
  }

  .search_fd1_1_c0_c1 {
    width: 18rpx;
    height: 18rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .search_fd1_1_c0_c0 {
    font-size: 24rpx;
    font-weight: 400;
    color: rgba(51, 51, 51, 1);
    margin: 0rpx 16rpx 0rpx 0rpx;
    -webkit-line-clamp: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    max-width: 200rpx;
    line-height: 56rpx;
  }

  .search_fd1_1_c0 {
    background: var(--benbenbgColor5);
    border-radius: 32rpx 32rpx 32rpx 32rpx;
    background-size: 100% auto !important;
    padding: 0rpx 40rpx 0rpx 40rpx;
    line-height: 56rpx;
    margin: 0rpx 12rpx 24rpx 12rpx;
  }

  .search_fd1_1 {
    padding: 0rpx 0rpx 0rpx 12rpx;
  }

  .search_fd1_0_c2 {
    width: 24rpx;
    height: 28rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    margin: 0rpx 0rpx 0rpx auto;
  }

  .search_fd1_0_c1 {
    font-size: 32rpx;
    font-weight: 500;
    color: rgba(51, 51, 51, 1);
  }

  .search_fd1_0_c0 {
    background: var(--benbenbgColor7);
    width: 6rpx;
    height: 24rpx;
    margin: 0rpx 10rpx 0rpx 10rpx;
    transform: scaleX(0.5);
  }

  .search_fd1_0 {
    padding: 32rpx 0rpx 24rpx 0rpx;
    margin: 0rpx 24rpx 0rpx 24rpx;
  }

  .search_flex_2 {
    background: var(--benbenbgColor1);
    margin: 0rpx 105rpx 0rpx 105rpx;
    background-size: #eee;
    border-radius: 25rpx 25rpx 25rpx 25rpx;
    padding: 40rpx 0rpx 0rpx 0rpx;
  }

  .search_fd2_2_c1 {
    background: var(--benbenbgColor1);
    line-height: 110rpx;
    border-radius: 0rpx 0rpx 16rpx 0rpx;
    font-size: 32rpx;
    color: var(--benbenFontColor7);
    width: 269rpx;
    height: 110rpx;
  }

  .search_fd2_2_c0 {
    border-right: 1px solid #EEEEEE;
    background: var(--benbenbgColor1);
    line-height: 110rpx;
    border-radius: 0rpx 0rpx 0rpx 16rpx;
    font-size: 32rpx;
    color: var(--benbenFontColor2);
    height: 110rpx;
    width: 270rpx;
  }

  .search_fd2_2 {
    border-top: 1px solid #eee;
  }

  .search_fd2_1 {
    font-size: 32rpx;
    font-weight: 400;
    line-height: 52rpx;
    color: #333333;
    margin: 40rpx 0rpx 39rpx 0rpx;
  }

  .search_fd2_0 {
    color: #333333;
    font-size: 32rpx;
    font-weight: 500;
    line-height: 45rpx;
  }
</style>
